package com.dmzapp.api.servlet;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;

import com.dmzapp.api.cache.redis.RedisClient;

/**
 * Servlet implementation class for Servlet: DownloadCountServlet
 * 
 */
public class DownloadCountServlet extends com.dmzapp.api.servlet.DMZSerlvet implements javax.servlet.Servlet {
    static final long serialVersionUID = 1L;
    private ObjectMapper mapper = new ObjectMapper();
    /*
     * (non-Java-doc)
     * 
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     */
    public DownloadCountServlet() {
        super();
    }

    @Override
    protected void handle(HttpServletRequest request, HttpServletResponse response) {

        long count = RedisClient.getInstance().downloadCount(System.getProperty("apkversioncode"));
        Map<String, Object> responseMap = new HashMap<String, Object>();
        responseMap.put("download_count", count);
        try {
            mapper.writeValue(response.getWriter(), responseMap);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}